home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-07-03 | 1.8 KB | 58 lines | [TEXT/R*ch] |
- (* Char -- new basis 1995-05-01 *)
-
- type char = char
- (* Invariant: for c: char it holds that 0 <= ord c <= maxOrd *)
-
- exception Chr = Chr
-
- local
- prim_val sub_ : string -> int -> char = 2 "get_nth_char"
- prim_val chr_ : int -> char = 1 "identity";
- in
- prim_val ord : char -> int = 1 "identity";
- val minChar = #"\000"
- val maxChar = #"\255"
- val maxOrd = 255;
-
- fun chr i = if i<0 orelse i>maxOrd then raise Chr else chr_ i;
-
- fun succ c =
- if c < maxChar then chr_(ord c + 1) else raise Chr;
- fun pred c =
- if c > minChar then chr_(ord c - 1) else raise Chr;
-
- fun contains s c =
- let val stop = size s
- fun h i = i < stop andalso (c = sub_ s i orelse h(i+1))
- in h 0 end;
-
- fun notContains s c = not (contains s c);
-
- fun isLower c = (#"a" <= c andalso c <= #"z")
- fun isUpper c = (#"A" <= c andalso c <= #"Z")
- fun isDigit c = (#"0" <= c andalso c <= #"9")
- fun isAlpha c = (isLower c orelse isUpper c)
- fun isHexDigit c = (isDigit c orelse #"a" <= c andalso c <= #"f"
- orelse #"A" <= c andalso c <= #"F")
- fun isAlphaNum c = (isAlpha c orelse isDigit c)
- fun isPrint c = c >= #" " andalso c <> #"\127" andalso c <> #"\255"
- fun isSpace c = contains " \009\010\011\012\013" c;
- fun isGraph c = isPrint c andalso not (isSpace c)
- fun isAscii c = c <= #"\127"
-
- fun toLower c =
- if #"A" <= c andalso c <= #"Z" then chr_(ord c + 32)
- else c;
- fun toUpper c =
- if #"a" <= c andalso c <= #"z" then chr_(ord c - 32)
- else c;
-
- fun cmp (x, y: char) =
- if x<y then LESS else if x>y then GREATER else EQUAL;
-
- val op < = op < : char * char -> bool;
- val op <= = op <= : char * char -> bool;
- val op > = op > : char * char -> bool;
- val op >= = op >= : char * char -> bool;
- end
-